import { Controller, Get, Put, Body, UseGuards } from '@nestjs/common'
import { Responser } from '@app/decorators/responser.decorator'
import { AuthUserGuard } from '@app/guards/auth-user.guard'
import { OptionService } from './option.service'
import { Option } from './option.model'

@Controller('option')
export class OptionController {
  constructor(private readonly optionService: OptionService) { }

  @Get()
  @UseGuards(AuthUserGuard)
  @Responser.handle('Get site options')
  getOption() {
    // getOption(@QueryParams() { isAuthenticated }: QueryParamsResult) {
    return this.optionService.ensureAppOption()
    // return isAuthenticated ? this.optionService.ensureAppOption() : this.optionService.getOptionCacheForGuest()
  }

  @Put()
  @UseGuards(AuthUserGuard)
  @Responser.handle('Update site options')
  putOption(@Body() option: Option): Promise<Option> {
    return this.optionService.putOption(option)
  }
}
